<?php

class Controller_Booking extends Controller_Site
{

	public function action_index()
	{
        if ( !Session::get('USER_ID') )
        {
            Session::set('url',Uri::create('booking'));
            Response::redirect('login');
        }
        else
        {
            Response::redirect('booking/form');
        }

	}

	public function action_login()
	{

	}

    public function action_form()
    {

        if ( !Session::get('USER_ID') )
        {
            Session::set('url',Uri::create('booking'));
            Response::redirect('login');
        }
        $this->set('times', Helper\Date::times());

        if ( Input::is_ajax() && Input::method() == 'POST' )
        {
            $arr = array();
            $arr['client_firstname']    = Input::post('client_firstname');
            $arr['client_lastname']     = Input::post('client_lastname');
            $arr['client_mobile']       = Input::post('client_mobile');
            $arr['client_email']        = Input::post('client_email');
            $arr['date']                = Input::post('date');
            $arr['from_time']           = Input::post('from_time');
            $arr['to_time']             = Input::post('to_time');
            $arr['meeting_type']        = Input::post('meeting_type');
            $arr['room_type']           = Input::post('room_type');
            $arr['description_booking'] = Input::post('description_booking');

            Session::set('arr_book',$arr);

            Lib\Response::json(array (
                'redirect' => Uri::create('booking/review')
            ), true);
        }
    }



	public function action_find()
	{
		
	}

	public function action_search()
	{
		
	}

	public function action_review()
	{

	}

	public function action_payment()
	{
		
	}

	public function action_thank()
	{
		
	}

	public function action_finish()
	{
		
	}

    public function action_save()
    {
        if ( Input::is_ajax() && Input::method() == 'POST' )
        {
            $arr= Session::get('arr_book');
            $user = Session::get('USER');
            DB::insert('booking')->set(array (
                'user_id' => $user['id'],
                'booked_for' => $arr['client_email'],
                'lsp_type' => 'freelancer',
                'lsp_id' => '12',
                'contact_id' => '24',
                'booking_date' => DB::expr('NOW()'),
                'date' => $arr['date'],
                'from_time' => $arr['from_time'],
                'to_time' => $arr['to_time'],
                'fee' => /*$arr['fee']*/'200',
                'venue_address' => /*$arr['venue_address']*/'aaaa',
                'meeting_type' => $arr['meeting_type'],
                'room_type' => $arr['room_type'],
                'number_of_client' => /*$arr['number_of_client']*/'3',
                'description' => $arr['description_booking'],
                'booking_status' => 'Awaiting',
                'update_timestamp' => '',
            ))->execute();

            Lib\Response::json(array (
                'redirect' => Uri::create('booking/finish')
            ), true);
        }
    }

}